<template>
  <el-card>
    <el-form
      :inline="true"
      :disabled="isCheckSelect"
      class="demo-form-inline mySelect"
    >
      <!-- 一级分类 -->
      <el-form-item label="一级分类">
        <el-select v-model="category1Id" placeholder="请选择">
          <el-option
            v-for="c1 in categoryStore.category1List"
            :key="c1.id"
            :label="c1.name"
            :value="c1.id"
          />
        </el-select>
      </el-form-item>
      <!-- 二级分类 -->
      <el-form-item label="二级分类">
        <el-select v-model="category2Id" placeholder="请选择">
          <el-option
            v-for="c2 in categoryStore.category2List"
            :key="c2.id"
            :label="c2.name"
            :value="c2.id"
          />
        </el-select>
      </el-form-item>
      <!-- 三级分类 -->
      <el-form-item label="三级分类">
        <el-select v-model="category3Id" placeholder="请选择">
          <el-option
            v-for="c3 in categoryStore.category3List"
            :key="c3.id"
            :label="c3.name"
            :value="c3.id"
          />
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script lang="ts">
export default {
  name: "CategoryList",
  props: ["isCheckSelect"],
}
</script>

<script lang="ts" setup>
import { ref, onMounted, computed } from "vue"
import { useCategoryListStore } from "@/stores/categoryList.ts"

const categoryStore = useCategoryListStore()

// 1 获取一级分类数据
onMounted(() => {
  categoryStore.getCategory1List()
})

// 2 获取二级分类数据
const category1Id = computed({
  get() {
    return categoryStore.category1Id as number
  },
  set(val: number) {
    categoryStore.getCategory2List(val)
  },
})

// 3 获取三级分类数据
const category2Id = computed({
  get() {
    return categoryStore.category2Id as number
  },
  set(val: number) {
    categoryStore.getCategory3List(val)
  },
})

// 4 设置获取三级分类Id
const category3Id = computed({
  get() {
    return categoryStore.category3Id as number
  },
  set(val: number) {
    categoryStore.setCategory3Id(val)
  },
})
</script>

<style lang="scss">
.mySelect {
  .el-form-item {
    margin-bottom: 0;
  }
}
</style>
